Write serial transmission code and upload it to the Modules page.
Peer review get_AD_value. Suggest changes if necessary.
Peer review store_sample. Suggest changes if necessary.
Hi Michael, I put this together for COUNT mode - I thought I would share it with you so you can see how I chose to wait for user input. Tell me if you think it will work.
count_mode(void){int i =0;char itemStr[4];
transmit(COUNT1);//You are in count mode. Please place one or more identical items on the scales.
totalMass = weigh();
transmit(int_to_string(totalMass));
transmit(COUNT2);//How many items are on the scales?//settings.recieveMode = RAW; //save numbers from string, don't interperet or change modes
numstart = recvbuf_iPtr;//Remember the start of the recieve string//Wait for an <enter>, then return the number from the recvstringwhile(*recvbuf_iPtr !=0x0D||*recvbuf_iPtr !=0x0A){//wait for an enter/lf to indicate user has entered a number}for(i =0; recvbuf_ePtr < recvbuf_iPtr; i++){
itemStr[i]=*recvbuf_ePtr;}
itemStr[i]=='\0';
items = str_to_int(itemStr);
itemMass = totalMass/items;
transmit(COUNT3);//Now, put an unknown number of items on the scales, then press enter.while(*recvbuf_iPtr !=0x0D||*recvbuf_iPtr !=0x0A){//wait for an enter/lf to indicate user is done}
transmit(int_to_string(getMass()/itemMass);}int str_to_int(char* string){int sum;int length =strlen(string);int multiplicand =1;for(length =strlen(string); length >0; length--){
sum +=(string[length]-'0')*multiplicand;
multiplicand *=10;}return sum;}
Michael West
Role: Integration and Software
To Do List:
Hi Michael, I put this together for COUNT mode - I thought I would share it with you so you can see how I chose to wait for user input. Tell me if you think it will work.